extends ../layout
block content
    script(src="/bower_components/cal-heatmap/cal-heatmap.min.js")
    script.
        var challengeName = 'Profile View';
    if (user && user.username === username)
      .row
        if (!user.isGithubCool)
          a.btn.btn-lg.btn-block.btn-github.btn-link-social(href='/link/github')
              i.fa.fa-github
              | 链接GitHub开启作品集
        .col-xs-12
            a.btn.btn-lg.btn-block.btn-primary.btn-link-social(href='/settings')
                | 更新设置
        .spacer
    h1.text-center #{username}的编码作品集
    hr
    .row
        .col-xs-12.col-sm-10.col-sm-offset-1.col-md-8.col-md-offset-2.text-center
            if picture
                img.img-center.img-responsive.public-profile-img(src=picture)
            else
                img.img-center.img-responsive.public-profile-img(src='/images/camper-image-placeholder.png')
            h1.text-center.negative-5.profile-social-icons
                if (github)
                    a.fa.fa-github-square.text-primary(title="@#{username}'s GitHub Profile", href=github, target='_blank')
            h1.flat-top.wrappable= name
            h1.flat-top.wrappable= location
            h1.flat-top.text-primary= "[ " + (progressTimestamps.length) + " ]"
            if pledge
                .spacer
                  h4
                    | This camper has committed to giving $#{pledge.amount} to
                    a(href='#{pledge.donateUrl}?ref=freecodecamp.cn' target='_blank')  #{pledge.displayName}
                    |  each month until they have completed their #{pledge.goal}.
                .spacer
            .row
                .col-xs-12.col-sm-10.col-sm-offset-1.col-md-8.col-md-offset-2
                    if isFrontEndCert
                        a.btn.btn-primary.btn-block(href='/' + username + '/front-end-certification') 查看我的前端开发认证
                    if isDataVisCert
                        .button-spacer
                        a.btn.btn-primary.btn-block(href='/' + username + '/data-visualization-certification') 查看我的数据可视化认证
                    if isBackEndCert
                        .button-spacer
                        a.btn.btn-primary.btn-block(href='/' + username + '/back-end-certification') 查看我的后端开发认证

    .spacer
    .col-md-12
        #cal-heatmap.hidden-xs.hidden-sm.d3-centered
            script.
                $(document).ready(function () {
                    var cal = new CalHeatMap();
                    var calendar = !{JSON.stringify(calender)};
                  /*
                    var estUTCOffset = -5;
                    // moment returns the utc offset in minutes
                    var userUTCOffset = moment().utcOffset() / 60;
                    var secondsToOffset =
                      (estUTCOffset - userUTCOffset) * 3600;
                    var offsetCalendar = {};
                    for (var prop in calendar) {
                      if (calendar.hasOwnProperty(prop)) {
                        var offsetProp = prop + secondsToOffset;
                        offsetCalendar[offsetProp] = calendar[prop];
                      }
                    }
                    */
                    cal.init({
                        itemSelector: "#cal-heatmap",
                        domain: "month",
                        subDomain: "x_day",
                        domainGutter: 10,
                        data: calendar,
                        cellSize: 15,
                        align: 'center',
                        cellRadius: 3,
                        cellPadding: 2,
                        tooltip: true,
                        range: 6,
                        start: new Date().setDate(new Date().getDate() - 150),
                        legendColors: ["#cccccc", "#215f1e"],
                        legend: [1, 2, 3],
                        label: {
                            position: "top"
                        }
                    });
                });
        .row
            .hidden-xs.col-sm-12.text-center
                .row.text-primary
                    h4.col-sm-6.text-right 最高频率: #{longestStreak} #{longestStreak === 1 ? ' day' : ' days'}
                    h4.col-sm-6.text-left  当前频率: #{currentStreak} #{currentStreak === 1 ? ' day' : ' days'}


          if (user && user.username == username || !isLocked)
              if (projects .length > 0)
                  .col-sm-12
                      table.table.table-striped
                          thead
                              tr
                                  th.col-xs-5 Projects
                                  th.col-xs-2.hidden-xs Completed
                                  th.col-xs-2.hidden-xs Last Updated
                                  th.col-xs-2.hidden-xs Link
                          for challenge in projects
                              tr
                                  td.col-xs-5.hidden-xs
                                      a(href='/challenges/' + removeOldTerms(challenge.name), target='_blank')= removeOldTerms(challenge.name)
                                  td.col-xs-2.hidden-xs= challenge.completedDate ? challenge.completedDate : 'Not Available'
                                  td.col-xs-2.hidden-xs= challenge.lastUpdated ? challenge.lastUpdated : ''
                                  td.col-xs-2.hidden-xs
                                      a(href=challenge.solution, target='_blank') View my project
                                  td.col-xs-12.visible-xs
                                      a(href=challenge.solution, target='_blank')= removeOldTerms(challenge.name)
              if (algorithms.length > 0)
                  .col-sm-12
                      table.table.table-striped
                          thead
                              tr
                                  th.col-xs-5 算法
                                  th.col-xs-2.hidden-xs 完成
                                  th.col-xs-2.hidden-xs 最后更新
                                  th.col-xs-2.hidden-xs 解决方案
                          for challenge in algorithms
                              tr
                                  td.col-xs-5.hidden-xs= removeOldTerms(challenge.name)
                                  td.col-xs-2.hidden-xs= challenge.completedDate ? challenge.completedDate : 'Not Available'
                                  td.col-xs-2.hidden-xs= challenge.lastUpdated ? challenge.lastUpdated : ''
                                  td.col-xs-2.hidden-xs
                                    if (challenge.solution)
                                        a(href='/challenges/' + removeOldTerms(challenge.name) + '#?solution=' + encodeURIComponent(encodeFcc(challenge.solution)), target='_blank') View solution
                                    else
                                        a(href='/challenges/' + removeOldTerms(challenge.name)) View this challenge
                                  td.col-xs-12.visible-xs
                                    if (challenge.solution)
                                        a(href='/challenges/' + removeOldTerms(challenge.name) + '#?solution=' + encodeURIComponent(encodeFcc(challenge.solution)), target='_blank')= removeOldTerms(challenge.name)
                                    else
                                        a(href='/challenges/' + removeOldTerms(challenge.name))= removeOldTerms(challenge.name)
              if (challenges.length > 0)
                  .col-sm-12
                      table.table.table-striped
                          thead
                              tr
                                  th.col-xs-5 挑战
                                  th.col-xs-2.hidden-xs 完成
                                  th.col-xs-2.hidden-xs 最后更新
                                  th.col-xs-2.hidden-xs 解决方案
                          for challenge in challenges
                              tr
                                  td.col-xs-5.hidden-xs= removeOldTerms(challenge.name)
                                  td.col-xs-2.hidden-xs= challenge.completedDate ? challenge.completedDate : 'Not Available'
                                  td.col-xs-2.hidden-xs= challenge.lastUpdated ? challenge.lastUpdated : ''
                                  td.col-xs-2.hidden-xs
                                    if (challenge.solution)
                                        a(href='/challenges/' + removeOldTerms(challenge.name) + '#?solution=' + encodeURIComponent(encodeFcc(challenge.solution)), target='_blank') View solution
                                    else
                                        a(href='/challenges/' + removeOldTerms(challenge.name)) View this challenge
                                  td.col-xs-12.visible-xs
                                    if (challenge.solution)
                                        a(href='/challenges/' + removeOldTerms(challenge.name) + '#?solution=' + encodeURIComponent(encodeFcc(challenge.solution)), target='_blank')= removeOldTerms(challenge.name)
                                    else
                                        a(href='/challenges/' + removeOldTerms(challenge.name))= removeOldTerms(challenge.name)
